import time
import IPy
from pythonping import ping
from multiprocessing import Process
import subprocess
subprocess.call('>down.txt',shell=True)
subprocess.call('>up.txt',shell=True)
# ping 网段地址
def test_ip(ip):
    res = ping(ip,timeout=1)
    time.sleep(2)
    if res.success():
        subprocess.call('echo %s 已经被使用 >>up.txt' % str(ip), shell=True)
    else:
        subprocess.call('echo %s 没有被使用 >>down.txt' % str(ip), shell=True)

#扫描的网段“192.168.243.0/24”
ip_net="192.168.243.0/24"
ips = IPy.IP(ip_net)
p_lst = []
if __name__=='__main__':
    for ip in ips:
        p=Process(target=test_ip, args=(str(ip),))
        p_lst.append(p)
        p.start()
    [p.join() for p in p_lst]
